<?php
// we'll generate XML output
header('Content-Type: text/xml');
// generate XML header
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
// create the <response> element
echo '<response>';
require_once("includes/include.php");
class addFriendClass extends daobase {
	public $user_id;
	public function __construct(){
		session_start();
		$id = $_SESSION["userId"];
		$this->user_id = $id;
	}
	public function formDataFilter($str){
		$str = htmlspecialchars($str);
		$str = str_replace(chr(13),"<br />",$str);
		$str = str_replace(chr(32),"&nbsp;",$str);
		return $str;
	}
	public function addNewFriendClass($name){
		$name = $this->formDataFilter($name);
		$user_id = $this->user_id;
		$sql = "select id from friend_class where class_name ='$name' and user_id = '$user_id'";
		$names = $this->fetchit($sql);
		if ($names[0][0]!=''){
			$sql = "select * from friend_class where user_id = '$user_id' and class_name='$name'";
			$names = $this->fetchit($sql);
			return $names;
		}
		else {
			$user_id = $this->user_id;
			$sql = "insert into friend_class(user_id,class_name) values('$user_id','$name')";
			$query = $this->queryit($sql);
			$sql = "select * from friend_class where user_id = '$user_id' and class_name='$name'";	 
			$names = $this->fetchit($sql);
			return $names;
	    }
	}		
}
$add = new addFriendClass();
$name = $_GET["className"];
$addResult = $add->addNewFriendClass("$name");
$classId = $addResult[0][0];
$className = $addResult[0][2];
echo "<newnameId>$classId</newnameId>";
echo "<newname>$className</newname>";
echo '</response>';
?>